package 重温_Java并发基础.code.future;

/**
 * @author idea
 * @data 2020/2/15
 */
public class Client {

    private FutureData futureData;

    public void request(CallableTask callableTask){
        futureData=new FutureData();
        futureData.setCallableTask(callableTask);
    }

    public Object get() throws InterruptedException {
        if(futureData==null){
            throw new RuntimeException("futureData can not be null!");
        }
        return futureData.get();
    }


    static class job implements CallableTask<String>{
        @Override
        public String run() {
            System.out.println("this is run");
            return "ten";
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Client client=new Client();
        client.request(new job());
        for(int i=0;i<10;i++){
            Thread.sleep(10);
            System.out.println("=======");
        }
        Object result = client.get();
        System.out.println(result);
    }

}
